'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }
  // stationData
  router.get('/api/stationData/list', controller.stationData.allList);
  router.post('/api/stationData/updateAll', controller.stationData.update);
  // energyData
  router.get('/api/energyData/list', controller.energyData.allList);
  router.post('/api/energyData/updateAll', controller.energyData.update);
  // pvForecastRel
  router.get('/api/pvForecastRel/list', controller.pvForecastRel.allList);
  router.post('/api/pvForecastRel/updateAll', controller.pvForecastRel.update);
  // pvForecastRelRecord
  router.get('/api/pvForecastRelRecord/list', controller.pvForecastRelRecord.allList);
  router.resources('pvForecastRelRecord', '/api/pvForecastRelRecord', controller.pvForecastRelRecord);
  // energyTimeData
  router.get('/api/energyTimeData/list', controller.energyTimeData.allList);
  router.post('/api/energyTimeData/upload', controller.energyTimeData.upload);
  router.resources('energyTimeData', '/api/energyTimeData', controller.energyTimeData);
  // 会员
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);

  // pvCoordination
  router.get('/api/pvCoordination/list', controller.pvCoordination.allList);
  router.post('/api/pvCoordination/updateAll', controller.pvCoordination.update);
  // pvCoordinationRecord
  router.get('/api/pvCoordinationRecord/list', controller.pvCoordinationRecord.allList);
  router.resources('pvCoordinationRecord', '/api/pvCoordinationRecord', controller.pvCoordinationRecord);
  // dataQuery
  router.get('/api/dataQuery/list', controller.dataQuery.allList);
  router.resources('dataQuery', '/api/dataQuery', controller.dataQuery);
  // alarm
  router.get('/api/alarm/list', controller.alarm.allList);
  router.resources('alarm', '/api/alarm', controller.alarm);
  // alarm
  router.get('/api/system/list', controller.system.allList);
  router.resources('system', '/api/system', controller.system);
  // role
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);
};
